package com.linkage.educloud.ah.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.bean.PersonInfo;
import com.linkage.educloud.ah.widget.MyMore;

import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/17.
 */

public class PersonTeacherAdapter extends android.widget.BaseAdapter {

    private Context mContext;
    private List<PersonInfo.ClassInfo> mList;

    public PersonTeacherAdapter(Context context, List<PersonInfo.ClassInfo> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public PersonInfo.ClassInfo getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_personinfo_teacher, null);
            viewHolder = new ViewHolder();
            viewHolder.item_personinfo_teacher_title = convertView.findViewById(R.id.item_personinfo_teacher_title);
            viewHolder.item_personinfo_teacher_school = convertView.findViewById(R.id.item_personinfo_teacher_school);
            viewHolder.item_personinfo_teacher_grade = convertView.findViewById(R.id.item_personinfo_teacher_grade);
            viewHolder.item_personinfo_teacher_class = convertView.findViewById(R.id.item_personinfo_teacher_class);
            viewHolder.item_personinfo_teacher_teach = convertView.findViewById(R.id.item_personinfo_teacher_teach);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        PersonInfo.ClassInfo info = getItem(position);
        if (position == 0) {
            viewHolder.item_personinfo_teacher_title.setVisibility(View.VISIBLE);
        } else {
            viewHolder.item_personinfo_teacher_title.setVisibility(View.GONE);
        }
        viewHolder.item_personinfo_teacher_school.setRightText(info.getSchool());
        viewHolder.item_personinfo_teacher_grade.setRightText(info.getGradename());
        viewHolder.item_personinfo_teacher_class.setRightText(info.getClassname());
        viewHolder.item_personinfo_teacher_teach.setRightText(info.getSubject());
        return convertView;
    }

    private class ViewHolder {
        TextView item_personinfo_teacher_title;
        MyMore item_personinfo_teacher_school;
        MyMore item_personinfo_teacher_grade;
        MyMore item_personinfo_teacher_class;
        MyMore item_personinfo_teacher_teach;
    }
}
